<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // const p = {
        //     name: 'zhangsan',
        //     age: 18,
        //     color: 'red',
        // };

        // // const expect1 = ['zhangsan', 18, 'red'];
        // // const expect2 = ['name', 'age', 'color'];

        // const res = [];
        // // for (const key in p) {
        // //     // const value = p[key];
        // //     res.push(key);
        // // }

        // for (const key in p) {
        //     res.push(key);
        // }

        // console.log(res);

        // const score = {
        //     zhangsan: 100,
        //     lisi: 0,
        //     wangwu: 99,
        //     liuliu: 59,
        // };

        // const res = [];
        // for (const key in score) {
        //     const value = score[key];
        //     res.push(value);
        // }

        // console.log(res);


        // // [100, 0, 99, 59]
        // console.log(  Object.values(score)  );
        // // ['zhangsan', 'lisi', 'wangwu', 'liuliu']
        // console.log( Object.keys(score) );


        const p = {
            name: 'zhangsan',
            age: 18,
            children: [
                {
                    name: 'lisi',
                    age: 18,
                    children: [
                        {
                            name: 'li5',
                            age: 18,
                            children: [
                                {
                                    name: 'xiao5',
                                    age: 11,
                                },
                                {
                                    name: 'xiao3',
                                    age: 14,
                                },
                            ],
                        },
                        {
                            name: 'li6',
                            age: 18,
                        },
                    ],
                },
                {
                    name: 'wangwu',
                    age: 19,
                },
                {
                    name: 'liuliu',
                    age: 20,
                    children: [
                        {
                            name: 'liu7',
                            age: 11,
                        },
                    ],
                },
            ],
        };

        // const expect = ['lisi', 'wangwu', 'liuliu'];
        // const res = [];
        // for (const item of p.children) {
        //     res.push(item.name);
        // }
        // console.log(res);

        // console.log(p.children.map((item) => item.name));

        // 打印出家族中所有的名字
        // function logNames (obj) {
        //     console.log(obj.name);
        //     for (const child of obj.children || []) {
        //         logNames(child);
        //     }
        // }

        // logNames(p);

        const person = {
            name: 'yuzelin',
            score: 99,
            students: [
                {
                    name: 'fangyunchuan',
                    score: 100,
                },
                {
                    name: 'zenghonggui',
                    score: 120,
                },
                {
                    name: 'junge',
                    score: 190,
                    students: [
                        {
                            name: 'chenwen',
                            score: 220,
                        },
                        {
                            name: 'zhongge',
                            score: 110,
                        },
                    ],
                },
            ],
        };

        // 打印所有人的名字
        function logNames (p) {
            console.log(p.name);
            for (const student of p.students || []) {
                logNames(student);
            }
        }

        logNames(person);

        // 求所有人的分数之和

        let sum = 0;
        function add (p) {
            console.log(p.score);
            sum += p.score;
            for (const student of p.students || []) {
                add(student);
            }
        }

        add(person);




    </script>
</body>
</html>